# 1、导包
import pymysql
# 2、创建连接，连接数据库
conn = pymysql.connect(user="root",  # The first four arguments is based on DB-API 2.0 recommendation.
        password="123456",
        host="localhost",
        database="books",
        port = 3306,
        autocommit=True)


# 3、获取游标
cursor = conn.cursor()
# 需求：插入一条数据
# sql = "insert into t_book(id,title,pub_date,`read`,`comment`) VALUES (8,'平凡的世界','1990-05-11',100,40)"

# 修改一条数据
# sql = "update t_book set title=\"新翻拍天龙八部\"  where title = \"天龙八部\""
# 删除一条数据

# 4、执行sql
sql = "delete from t_book where title =\"平凡的世界\""

cursor.execute(sql)

# 当执行的不是查询语句时，cursor.rownumber表示的是影响的数据行数
print("影响的数据：",cursor.rowcount)

cursor.close()
# 7、关闭连接
conn.close()
